﻿<%@ Page Language="C#" AutoEventWireup="true" %>
<%@ Import Namespace="System.Collections.Generic"%>
<%@ Import Namespace="com.bodurov.SessionRecovery"%>
<script language="C#" runat="server">
private void BindControl(object sender, EventArgs e)
{
    ((Control) sender).DataBind();
}
private void ToggleSessionRecovery(object sender, EventArgs e)
{
    Sessions.Manager.IsEnabled = !Sessions.Manager.IsEnabled;
}
private void AddNewSessionKey(object sender, EventArgs e)
{
    var key = this.SessionKey.Text;
    if(String.IsNullOrEmpty(key))
    {
        return;
    }
    this.Session[key] = this.SessionValue.Text;
}
public IEnumerable<KeyValuePair<string, string>> SessionContents
{
    get
    {
        foreach(var sessionKey in this.Session.Keys)
            yield return new KeyValuePair<string, string>(
                                sessionKey.ToString(), 
                                this.Session[sessionKey.ToString()]+""
                              );
        
    }
}
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>
    <style>
* {
	font-family: Georgia;
}
    </style>
    <script type="text/javascript">
    function RefreshUnique()
    {
        var loc = document.location.href;
        var qmIndex = loc.indexOf('?');
        if (qmIndex > 0) {
            loc = loc.substr(0, qmIndex);
        }
        document.location.href = loc + "?u=" + (new Date()).getTime();
    }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <div>
            Session Recovery is
            <strong>
                <asp:Label runat="server" OnPreRender="BindControl" 
                     Text='<%#Sessions.Manager.IsEnabled?"Enabled":"Disabled"%>' />
            </strong> 
            <asp:Button runat="server" OnPreRender="BindControl" OnClick="ToggleSessionRecovery"
                 Text='<%#Sessions.Manager.IsEnabled?"Disable!":"Enable!"%>' />
            <input type="button" value="Refresh The Page" onclick="RefreshUnique();return false;" />
        </div>
        <div>&nbsp;</div>
        <div>
            <div>Add Session Key : Value</div>
            <div>&nbsp;</div>
            <div>
                Key: <asp:TextBox ID="SessionKey" Width="60px" runat="server" Text="Key1"></asp:TextBox>
                Value: <asp:TextBox ID="SessionValue" Width="100px" runat="server" Text="Value1"></asp:TextBox>
                <asp:Button ID="Button1" runat="server" OnClick="AddNewSessionKey" Text="Add" />
            </div> 
        </div>
        <div>&nbsp;</div>
        <div>
            <div>Current Session Contents : <strong><asp:Label ID="Label1" runat="server" OnPreRender="BindControl" 
                     Text='<%#this.Session.Count.ToString()%>' /></strong> item(s)</div>
            <hr width="300px" align="left"/>
            <asp:Repeater runat="server" OnPreRender="BindControl" DataSource='<%#SessionContents%>'>
                <ItemTemplate>
                    <div><strong><%#Eval("Key")%></strong>:<%#Eval("Value")%></div>
                </ItemTemplate>
            </asp:Repeater>
        </div>
    </div>
    <div>&nbsp;</div>
    <div>&nbsp;</div>
    <div>&nbsp;</div>
    <div>&nbsp;</div>
    <div>Common Scenario:</div>
    <ol>
        <li>Set <strong>Sessions.Manager.IsEnabled = true</strong> (in this UI click on the button Enable!)</li>
        <li>Make any changes in the <strong>bin</strong> folder or in the <strong>web.config</strong> file</li>
        <li>Set <strong>Sessions.Manager.IsEnabled = false</strong> (in this UI click on the button Disable!)</li>
        <li>Check that your session is has been restored.</li>
    </ol>
    </form>
</body>
</html>
